package com.googlecode.jcaffe.control.modules.settingswindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

final class SettingsWindowController implements ActionListener, ListSelectionListener {
	private SettingsWindowView view;
	@SuppressWarnings("unused")
	private SettingsWindowModel model;

	public SettingsWindowController(SettingsWindowView view, SettingsWindowModel model) {
		this.view = view;
		this.model = model;

		view.setEventListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent event) {
		String actionCommand = event.getActionCommand();

		if ("exit".equals(actionCommand)) {
			view.dispose();
		}
		else if ("save".equals(actionCommand)) {
			//TODO: Implement saving settings.
		}
	}

	@Override
	public void valueChanged(ListSelectionEvent event) {
		int selectedItemIndex = view.getSelectedSettingIndex();

		if ((event.getValueIsAdjusting() == false) && (selectedItemIndex != -1)) {
			String settingValue = view.getSelectedSettingValue();

			if (settingValue.equals("Database")) {
				view.displayDatabaseSettings();
			}
		}
	}
}
